package service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import entity.Customer;
import entity.LayRequest;
import mapper.CustomerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CustomerServiceImpl implements CustomerService{
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public boolean insert(Customer customer) {
        return customerMapper.insert(customer)>0?true:false;
    }

    @Override
    public Customer selectById(Integer id) {
        return customerMapper.selectById(id);
    }

    @Override
    public PageInfo<Customer> selectByPage(LayRequest layRequest) {
        PageHelper.startPage(layRequest.getPage(),layRequest.getLimit());
        List<Customer> customers = customerMapper.selectByPage(layRequest.getParams());
        PageInfo<Customer> customerPageInfo = new PageInfo<>(customers);
        return customerPageInfo;
    }


    @Override
    public boolean update(Customer customer) {
        return customerMapper.update(customer)>0?true:false;
    }

    @Override
    public boolean batchDelete(Integer[] ids) {
        return customerMapper.batchDelete(ids)>0?true:false;
    }

    @Override
    public List<Customer> selectAll() {
        return customerMapper.selectAll();
    }
}
